<?php
/***************************************************************
*  Copyright notice
*  (c) 2009, jianyuzhu@gmail.com
*  All rights reserved
*  This script is part of the PPEMI project.
***************************************************************/

//
include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'frontend.main.class.php');
$feObj = new FrontendMainBase();

//
include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'module/download/download.class.php');
$mObj = new DownloadBase();

//
if( $request_link_class == 'file' ) {
	$link = $request_link_subclass;
	if( $link != '' ) {
		$item = $mObj->getItem($link, 'link');
		//
		$file = CONFIG_PATH . CONFIG_DIR_UPLOADS_ORIGINS . $item['file'];
		if( $item['id'] > 0 && $item['file'] != '' && is_file($file) ) {
			//
			include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'lib.mime.class.php');
			$mimeObj = new LibMime();
			$mimetype = $mimeObj->getMimeType($file);
			
			//
			$filesize = filesize($file);
			
			//
			$mObj->addDownloadCount($item['id']);
			
			//
			header('Content-Type: '.$mimetype);
			header('Content-Length: '.$filesize);
			header('Content-disposition: attachment; filename=' . $item['filename']);
			
			readfile($file);
			exit();
		}
	}
}

//
$items = $mObj->getItems('', 0, false);
$feObj->addInject('items', $items);

//
echo $feObj->display('pagelayout/pagelayout_main_download.tpl');
//
?>